home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JList.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  12.8 KB  |  536 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.Insets;
  9. import java.awt.Point;
  10. import java.awt.Rectangle;
  11. import java.io.IOException;
  12. import java.io.ObjectOutputStream;
  13. import java.util.Vector;
  14. import javax.accessibility.Accessible;
  15. import javax.accessibility.AccessibleContext;
  16. import javax.swing.event.ListSelectionEvent;
  17. import javax.swing.event.ListSelectionListener;
  18. import javax.swing.plaf.ListUI;
  19.  
  20. public class JList extends JComponent implements Scrollable, Accessible {
  21.    private static final String uiClassID = "ListUI";
  22.    private int fixedCellWidth;
  23.    private int fixedCellHeight;
  24.    private int horizontalScrollIncrement;
  25.    private Object prototypeCellValue;
  26.    private int visibleRowCount;
  27.    private Color selectionForeground;
  28.    private Color selectionBackground;
  29.    private ListSelectionModel selectionModel;
  30.    private ListModel dataModel;
  31.    private ListCellRenderer cellRenderer;
  32.    private ListSelectionListener selectionListener;
  33.    // $FF: synthetic field
  34.    static Class class$javax$swing$event$ListSelectionListener;
  35.  
  36.    public JList() {
  37.       this((ListModel)(new 3()));
  38.    }
  39.  
  40.    public JList(Vector var1) {
  41.       this((ListModel)(new 2(var1)));
  42.    }
  43.  
  44.    public JList(ListModel var1) {
  45.       this.fixedCellWidth = -1;
  46.       this.fixedCellHeight = -1;
  47.       this.horizontalScrollIncrement = -1;
  48.       this.visibleRowCount = 8;
  49.       if (var1 == null) {
  50.          throw new IllegalArgumentException("dataModel must be non null");
  51.       } else {
  52.          this.dataModel = var1;
  53.          this.selectionModel = this.createSelectionModel();
  54.          ((JComponent)this).setAutoscrolls(true);
  55.          ((JComponent)this).setOpaque(true);
  56.          this.updateUI();
  57.       }
  58.    }
  59.  
  60.    public JList(Object[] var1) {
  61.       this((ListModel)(new 1(var1)));
  62.    }
  63.  
  64.    // $FF: synthetic method
  65.    static ListSelectionModel access$0(JList var0) {
  66.       return var0.selectionModel;
  67.    }
  68.  
  69.    public void addListSelectionListener(ListSelectionListener var1) {
  70.       if (this.selectionListener == null) {
  71.          this.selectionListener = new ListSelectionHandler(this);
  72.          this.getSelectionModel().addListSelectionListener(this.selectionListener);
  73.       }
  74.  
  75.       super.listenerList.add(class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")), var1);
  76.    }
  77.  
  78.    public void addSelectionInterval(int var1, int var2) {
  79.       this.getSelectionModel().addSelectionInterval(var1, var2);
  80.    }
  81.  
  82.    // $FF: synthetic method
  83.    static Class class$(String var0) {
  84.       try {
  85.          return Class.forName(var0);
  86.       } catch (ClassNotFoundException var2) {
  87.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  88.       }
  89.    }
  90.  
  91.    public void clearSelection() {
  92.       this.getSelectionModel().clearSelection();
  93.    }
  94.  
  95.    protected ListSelectionModel createSelectionModel() {
  96.       return new DefaultListSelectionModel();
  97.    }
  98.  
  99.    public void ensureIndexIsVisible(int var1) {
  100.       Rectangle var2 = this.getCellBounds(var1, var1);
  101.       if (var2 != null) {
  102.          ((JComponent)this).scrollRectToVisible(var2);
  103.       }
  104.  
  105.    }
  106.  
  107.    protected void fireSelectionValueChanged(int var1, int var2, boolean var3) {
  108.       Object[] var4 = super.listenerList.getListenerList();
  109.       ListSelectionEvent var5 = null;
  110.  
  111.       for(int var6 = var4.length - 2; var6 >= 0; var6 -= 2) {
  112.          if (var4[var6] == (class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")))) {
  113.             if (var5 == null) {
  114.                var5 = new ListSelectionEvent(this, var1, var2, var3);
  115.             }
  116.  
  117.             ((ListSelectionListener)var4[var6 + 1]).valueChanged(var5);
  118.          }
  119.       }
  120.  
  121.    }
  122.  
  123.    public AccessibleContext getAccessibleContext() {
  124.       if (super.accessibleContext == null) {
  125.          super.accessibleContext = new AccessibleJList(this);
  126.       }
  127.  
  128.       return super.accessibleContext;
  129.    }
  130.  
  131.    public int getAnchorSelectionIndex() {
  132.       return this.getSelectionModel().getAnchorSelectionIndex();
  133.    }
  134.  
  135.    public Rectangle getCellBounds(int var1, int var2) {
  136.       ListUI var3 = this.getUI();
  137.       return var3 != null ? var3.getCellBounds(this, var1, var2) : null;
  138.    }
  139.  
  140.    public ListCellRenderer getCellRenderer() {
  141.       return this.cellRenderer;
  142.    }
  143.  
  144.    public int getFirstVisibleIndex() {
  145.       Point var1 = ((JComponent)this).getVisibleRect().getLocation();
  146.       return this.locationToIndex(var1);
  147.    }
  148.  
  149.    public int getFixedCellHeight() {
  150.       return this.fixedCellHeight;
  151.    }
  152.  
  153.    public int getFixedCellWidth() {
  154.       return this.fixedCellWidth;
  155.    }
  156.  
  157.    public int getLastVisibleIndex() {
  158.       Rectangle var1 = ((JComponent)this).getVisibleRect();
  159.       Point var2 = new Point(var1.x + var1.width - 1, var1.y + var1.height - 1);
  160.       return this.locationToIndex(var2);
  161.    }
  162.  
  163.    public int getLeadSelectionIndex() {
  164.       return this.getSelectionModel().getLeadSelectionIndex();
  165.    }
  166.  
  167.    public int getMaxSelectionIndex() {
  168.       return this.getSelectionModel().getMaxSelectionIndex();
  169.    }
  170.  
  171.    public int getMinSelectionIndex() {
  172.       return this.getSelectionModel().getMinSelectionIndex();
  173.    }
  174.  
  175.    public ListModel getModel() {
  176.       return this.dataModel;
  177.    }
  178.  
  179.    public Dimension getPreferredScrollableViewportSize() {
  180.       Insets var1 = ((JComponent)this).getInsets();
  181.       int var2 = var1.left + var1.right;
  182.       int var3 = var1.top + var1.bottom;
  183.       int var4 = this.getVisibleRowCount();
  184.       int var5 = this.getFixedCellWidth();
  185.       int var6 = this.getFixedCellHeight();
  186.       if (var5 > 0 && var6 > 0) {
  187.          int var12 = var5 + var2;
  188.          int var13 = var4 * var6 + var3;
  189.          return new Dimension(var12, var13);
  190.       } else if (this.getModel().getSize() > 0) {
  191.          int var7 = ((JComponent)this).getPreferredSize().width;
  192.          Rectangle var8 = this.getCellBounds(0, 0);
  193.          int var9 = var4 * var8.height + var3;
  194.          return new Dimension(var7, var9);
  195.       } else {
  196.          var5 = var5 > 0 ? var5 : 256;
  197.          var6 = var6 > 0 ? var6 : 16;
  198.          return new Dimension(var5, var6 * var4);
  199.       }
  200.    }
  201.  
  202.    public Object getPrototypeCellValue() {
  203.       return this.prototypeCellValue;
  204.    }
  205.  
  206.    public int getScrollableBlockIncrement(Rectangle var1, int var2, int var3) {
  207.       return var2 == 1 ? var1.height : var1.width;
  208.    }
  209.  
  210.    public boolean getScrollableTracksViewportHeight() {
  211.       if (((Component)this).getParent() instanceof JViewport) {
  212.          return ((JViewport)((Component)this).getParent()).getHeight() > ((JComponent)this).getPreferredSize().height;
  213.       } else {
  214.          return false;
  215.       }
  216.    }
  217.  
  218.    public boolean getScrollableTracksViewportWidth() {
  219.       if (((Component)this).getParent() instanceof JViewport) {
  220.          return ((JViewport)((Component)this).getParent()).getWidth() > ((JComponent)this).getPreferredSize().width;
  221.       } else {
  222.          return false;
  223.       }
  224.    }
  225.  
  226.    public int getScrollableUnitIncrement(Rectangle var1, int var2, int var3) {
  227.       if (var2 == 0) {
  228.          Font var7 = ((Component)this).getFont();
  229.          return var7 != null ? var7.getSize() : 1;
  230.       } else {
  231.          int var4 = this.getFirstVisibleIndex();
  232.          if (var4 == -1) {
  233.             return 0;
  234.          } else if (var3 > 0) {
  235.             Rectangle var8 = this.getCellBounds(var4, var4);
  236.             return var8 == null ? 0 : var8.height - (var1.y - var8.y);
  237.          } else {
  238.             Rectangle var5 = this.getCellBounds(var4, var4);
  239.             if (var5.y == var1.y && var4 == 0) {
  240.                return 0;
  241.             } else if (var5.y == var1.y) {
  242.                Rectangle var6 = this.getCellBounds(var4 - 1, var4 - 1);
  243.                return var6 == null ? 0 : var6.height;
  244.             } else {
  245.                return var1.y - var5.y;
  246.             }
  247.          }
  248.       }
  249.    }
  250.  
  251.    public int getSelectedIndex() {
  252.       return this.getMinSelectionIndex();
  253.    }
  254.  
  255.    public int[] getSelectedIndices() {
  256.       ListSelectionModel var1 = this.getSelectionModel();
  257.       int var2 = var1.getMinSelectionIndex();
  258.       int var3 = var1.getMaxSelectionIndex();
  259.       if (var2 >= 0 && var3 >= 0) {
  260.          int[] var4 = new int[1 + (var3 - var2)];
  261.          int var5 = 0;
  262.  
  263.          for(int var6 = var2; var6 <= var3; ++var6) {
  264.             if (var1.isSelectedIndex(var6)) {
  265.                var4[var5++] = var6;
  266.             }
  267.          }
  268.  
  269.          int[] var7 = new int[var5];
  270.          System.arraycopy(var4, 0, var7, 0, var5);
  271.          return var7;
  272.       } else {
  273.          return new int[0];
  274.       }
  275.    }
  276.  
  277.    public Object getSelectedValue() {
  278.       int var1 = this.getMinSelectionIndex();
  279.       return var1 == -1 ? null : this.getModel().getElementAt(var1);
  280.    }
  281.  
  282.    public Object[] getSelectedValues() {
  283.       ListSelectionModel var1 = this.getSelectionModel();
  284.       ListModel var2 = this.getModel();
  285.       int var3 = var1.getMinSelectionIndex();
  286.       int var4 = var1.getMaxSelectionIndex();
  287.       if (var3 >= 0 && var4 >= 0) {
  288.          Object[] var5 = new Object[1 + (var4 - var3)];
  289.          int var6 = 0;
  290.  
  291.          for(int var7 = var3; var7 <= var4; ++var7) {
  292.             if (var1.isSelectedIndex(var7)) {
  293.                var5[var6++] = var2.getElementAt(var7);
  294.             }
  295.          }
  296.  
  297.          Object[] var8 = new Object[var6];
  298.          System.arraycopy(var5, 0, var8, 0, var6);
  299.          return var8;
  300.       } else {
  301.          return new Object[0];
  302.       }
  303.    }
  304.  
  305.    public Color getSelectionBackground() {
  306.       return this.selectionBackground;
  307.    }
  308.  
  309.    public Color getSelectionForeground() {
  310.       return this.selectionForeground;
  311.    }
  312.  
  313.    public int getSelectionMode() {
  314.       return this.getSelectionModel().getSelectionMode();
  315.    }
  316.  
  317.    public ListSelectionModel getSelectionModel() {
  318.       return this.selectionModel;
  319.    }
  320.  
  321.    public ListUI getUI() {
  322.       return (ListUI)super.ui;
  323.    }
  324.  
  325.    public String getUIClassID() {
  326.       return "ListUI";
  327.    }
  328.  
  329.    public boolean getValueIsAdjusting() {
  330.       return this.getSelectionModel().getValueIsAdjusting();
  331.    }
  332.  
  333.    public int getVisibleRowCount() {
  334.       return this.visibleRowCount;
  335.    }
  336.  
  337.    public Point indexToLocation(int var1) {
  338.       ListUI var2 = this.getUI();
  339.       return var2 != null ? var2.indexToLocation(this, var1) : null;
  340.    }
  341.  
  342.    public boolean isSelectedIndex(int var1) {
  343.       return this.getSelectionModel().isSelectedIndex(var1);
  344.    }
  345.  
  346.    public boolean isSelectionEmpty() {
  347.       return this.getSelectionModel().isSelectionEmpty();
  348.    }
  349.  
  350.    public int locationToIndex(Point var1) {
  351.       ListUI var2 = this.getUI();
  352.       return var2 != null ? var2.locationToIndex(this, var1) : -1;
  353.    }
  354.  
  355.    protected String paramString() {
  356.       String var1 = this.selectionForeground != null ? this.selectionForeground.toString() : "";
  357.       String var2 = this.selectionBackground != null ? this.selectionBackground.toString() : "";
  358.       return super.paramString() + ",fixedCellHeight=" + this.fixedCellHeight + ",fixedCellWidth=" + this.fixedCellWidth + ",horizontalScrollIncrement=" + this.horizontalScrollIncrement + ",selectionBackground=" + var2 + ",selectionForeground=" + var1 + ",visibleRowCount=" + this.visibleRowCount;
  359.    }
  360.  
  361.    public void removeListSelectionListener(ListSelectionListener var1) {
  362.       super.listenerList.remove(class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")), var1);
  363.    }
  364.  
  365.    public void removeSelectionInterval(int var1, int var2) {
  366.       this.getSelectionModel().removeSelectionInterval(var1, var2);
  367.    }
  368.  
  369.    public void setCellRenderer(ListCellRenderer var1) {
  370.       ListCellRenderer var2 = this.cellRenderer;
  371.       this.cellRenderer = var1;
  372.       if (var1 != null && !var1.equals(var2)) {
  373.          this.updateFixedCellSize();
  374.       }
  375.  
  376.       ((JComponent)this).firePropertyChange("cellRenderer", var2, var1);
  377.    }
  378.  
  379.    public void setFixedCellHeight(int var1) {
  380.       int var2 = this.fixedCellHeight;
  381.       this.fixedCellHeight = var1;
  382.       ((JComponent)this).firePropertyChange("fixedCellHeight", var2, this.fixedCellHeight);
  383.    }
  384.  
  385.    public void setFixedCellWidth(int var1) {
  386.       int var2 = this.fixedCellWidth;
  387.       this.fixedCellWidth = var1;
  388.       ((JComponent)this).firePropertyChange("fixedCellWidth", var2, this.fixedCellWidth);
  389.    }
  390.  
  391.    public void setListData(Vector var1) {
  392.       this.setModel(new 5(var1));
  393.    }
  394.  
  395.    public void setListData(Object[] var1) {
  396.       this.setModel(new 4(var1));
  397.    }
  398.  
  399.    public void setModel(ListModel var1) {
  400.       if (var1 == null) {
  401.          throw new IllegalArgumentException("model must be non null");
  402.       } else {
  403.          ListModel var2 = this.dataModel;
  404.          this.dataModel = var1;
  405.          ((JComponent)this).firePropertyChange("model", var2, this.dataModel);
  406.          this.clearSelection();
  407.       }
  408.    }
  409.  
  410.    public void setPrototypeCellValue(Object var1) {
  411.       Object var2 = this.prototypeCellValue;
  412.       this.prototypeCellValue = var1;
  413.       if (var1 != null && !var1.equals(var2)) {
  414.          this.updateFixedCellSize();
  415.       }
  416.  
  417.       ((JComponent)this).firePropertyChange("prototypeCellValue", var2, var1);
  418.    }
  419.  
  420.    public void setSelectedIndex(int var1) {
  421.       this.getSelectionModel().setSelectionInterval(var1, var1);
  422.    }
  423.  
  424.    public void setSelectedIndices(int[] var1) {
  425.       ListSelectionModel var2 = this.getSelectionModel();
  426.       var2.clearSelection();
  427.  
  428.       for(int var3 = 0; var3 < var1.length; ++var3) {
  429.          var2.addSelectionInterval(var1[var3], var1[var3]);
  430.       }
  431.  
  432.    }
  433.  
  434.    public void setSelectedValue(Object var1, boolean var2) {
  435.       if (var1 == null) {
  436.          this.setSelectedIndex(-1);
  437.       } else if (!var1.equals(this.getSelectedValue())) {
  438.          ListModel var5 = this.getModel();
  439.          int var3 = 0;
  440.  
  441.          for(int var4 = var5.getSize(); var3 < var4; ++var3) {
  442.             if (var1.equals(var5.getElementAt(var3))) {
  443.                this.setSelectedIndex(var3);
  444.                if (var2) {
  445.                   this.ensureIndexIsVisible(var3);
  446.                }
  447.  
  448.                ((Component)this).repaint();
  449.                return;
  450.             }
  451.          }
  452.  
  453.          this.setSelectedIndex(-1);
  454.       }
  455.  
  456.       ((Component)this).repaint();
  457.    }
  458.  
  459.    public void setSelectionBackground(Color var1) {
  460.       Color var2 = this.selectionBackground;
  461.       this.selectionBackground = var1;
  462.       ((JComponent)this).firePropertyChange("selectionBackground", var2, var1);
  463.    }
  464.  
  465.    public void setSelectionForeground(Color var1) {
  466.       Color var2 = this.selectionForeground;
  467.       this.selectionForeground = var1;
  468.       ((JComponent)this).firePropertyChange("selectionForeground", var2, var1);
  469.    }
  470.  
  471.    public void setSelectionInterval(int var1, int var2) {
  472.       this.getSelectionModel().setSelectionInterval(var1, var2);
  473.    }
  474.  
  475.    public void setSelectionMode(int var1) {
  476.       this.getSelectionModel().setSelectionMode(var1);
  477.    }
  478.  
  479.    public void setSelectionModel(ListSelectionModel var1) {
  480.       if (var1 == null) {
  481.          throw new IllegalArgumentException("selectionModel must be non null");
  482.       } else {
  483.          if (this.selectionListener != null) {
  484.             this.selectionModel.removeListSelectionListener(this.selectionListener);
  485.             var1.addListSelectionListener(this.selectionListener);
  486.          }
  487.  
  488.          ListSelectionModel var2 = this.selectionModel;
  489.          this.selectionModel = var1;
  490.          ((JComponent)this).firePropertyChange("selectionModel", var2, var1);
  491.       }
  492.    }
  493.  
  494.    public void setUI(ListUI var1) {
  495.       super.setUI(var1);
  496.    }
  497.  
  498.    public void setValueIsAdjusting(boolean var1) {
  499.       this.getSelectionModel().setValueIsAdjusting(var1);
  500.    }
  501.  
  502.    public void setVisibleRowCount(int var1) {
  503.       int var2 = this.visibleRowCount;
  504.       this.visibleRowCount = Math.max(0, var1);
  505.       ((JComponent)this).firePropertyChange("visibleRowCount", var2, var1);
  506.    }
  507.  
  508.    private void updateFixedCellSize() {
  509.       ListCellRenderer var1 = this.getCellRenderer();
  510.       Object var2 = this.getPrototypeCellValue();
  511.       if (var1 != null && var2 != null) {
  512.          Component var3 = var1.getListCellRendererComponent(this, var2, 0, false, false);
  513.          Font var4 = var3.getFont();
  514.          var3.setFont(((Component)this).getFont());
  515.          Dimension var5 = var3.getPreferredSize();
  516.          this.fixedCellWidth = var5.width;
  517.          this.fixedCellHeight = var5.height;
  518.          var3.setFont(var4);
  519.       }
  520.  
  521.    }
  522.  
  523.    public void updateUI() {
  524.       this.setUI((ListUI)UIManager.getUI(this));
  525.       ((Container)this).invalidate();
  526.    }
  527.  
  528.    private void writeObject(ObjectOutputStream var1) throws IOException {
  529.       var1.defaultWriteObject();
  530.       if (super.ui != null && this.getUIClassID().equals("ListUI")) {
  531.          super.ui.installUI(this);
  532.       }
  533.  
  534.    }
  535. }
  536.